package com.zl.learning.io.test.test;

/**
 * Created by zhaolei on 2017/5/2.
 */

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Program {
    static public void main( String args[] ) throws Exception {
        FileInputStream fin = new FileInputStream("demo/nio-out.txt");

        // 获取通道
        FileChannel fc = fin.getChannel();

        // 创建缓冲区
        ByteBuffer buffer = ByteBuffer.allocate(1024);
//        Charset charset = Charset.forName("UTF-8");


        // 读取数据到缓冲区
        fc.read(buffer);
        byte[] data =buffer.array();
        System.out.println(new String(data));
        buffer.flip();


        while (buffer.remaining()>0) {
            byte b = buffer.get();
            System.out.print(((char)b));
        }

        fin.close();
    }
}
